<style type="text/css">

</style>
<div id="layui-container" class="layui-anim layui-anim-downbit">
    <div class="layui-btn-container">
        <button class="layui-btn" type="button" lay-active="loadQrcodeImg">扫码验证</button>
        <button class="layui-btn" type="button" lay-active="qrScanStatus">二维码扫码状态</button>
        <button class="layui-btn" type="button" lay-active="doCheck">验证返回数据</button>
    </div>
    <div class="layui-row">
        <img id="qrImg" src="" alt=""/>
    </div>
</div>
<script type="text/javascript">
    layui.use(['util'], function () {
        let util = layui.util;

        let actionId;
        let accessResult;

        let active = {
            loadQrcodeImg: function () {
                request.bodyAjax(api.qrCodeImg, {
                    qrcodeType: 'CONFIRM',
                    extAttrs: {}
                }, function (res) {
                    if (res.success && res.status === 200) {
                        let $qrImg = $('#qrImg');
                        $qrImg.attr('src', api.viewCodeImg + res.data + "?n=" + new Date().getTime());

                        actionId = res.data;
                    }
                });
            },
            qrScanStatus: function (noToast, func) {
                request.bodyAjax(api.scanResult, {
                    actionId: actionId
                }, function (res) {
                    if (res.success && res.status === 200 && res.data !== false) {
                        layer.alert("二维码已被扫描, 详细信息请查看控制台");
                        accessResult = res.data;
                        console.log(res.data);
                    } else {
                        layer.msg("没有查询到已扫描状态");
                    }
                    if (func) {
                        func();
                    }
                });
            },
            doCheck: function () {
                request.bodyAjax(api.doCheck, accessResult, function (res) {
                    layer.alert(JSON.stringify(res));
                });
            }
        };

        // layui的btn单独添加点击事件
        util.event('lay-active', active);

    });
</script>
